using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Library;
using NCS.Library.Utilities;
using NCS.Library.Components.Partner;
using NCS.Module.Multimedia.Library;
using NCS.Module.Multimedia.Library.Bonus;
using NCS.Module.Multimedia.Library.Gallery;

namespace NCS.Module.Multimedia.Web
{
    public partial class LeftBottomNews : GalleryWebControl
    {
        public int zoneGalleryid;
        public int zoneBonusid;
        protected void Page_Load(object sender, EventArgs e)
        {
            int catid = ConvertUtility.ToInt32(Request.QueryString["catid"]);
            if (catid != 0)
            {
                Advertisement1.Param = "catid";
            }
            
            zoneGalleryid = ConvertUtility.ToInt32(Portal[Definies.CMS_MV_Gallery + AppEnv.GetLanguage()]);

            DataTable dtgallery = Gallery_AlbumController.GetAlbumByNum(4);
            rptGallery.DataSource = dtgallery;
            rptGallery.DataBind();

            //bonus
            zoneBonusid = ConvertUtility.ToInt32(Portal[Definies.CMS_MV_Bonus + AppEnv.GetLanguage()]);

            DataTable dtBonus = Gallery_BonusController.GetAllBonusByNum(4);
            rptBosnu.DataSource = dtBonus;
            rptBosnu.DataBind();

        }

        protected void rptGallery_ItemDataBound1(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemIndex < 0) return;
            DataRowView currow = (DataRowView)e.Item.DataItem;
            Image imgPic = (Image)e.Item.FindControl("imgPic");
            imgPic.ImageUrl = ConvertUtility.ToString(currow["AlbumAvatar"]) != string.Empty ? MultimediaUtility.GetGalleryAvatar(currow["AlbumAvatar"].ToString()) : "";
            if (imgPic.ImageUrl == "") imgPic.Visible = false;

            HyperLink hplTitle = (HyperLink)e.Item.FindControl("hplTitle");
            //hplTitle.Text = ConvertUtility.ToString(currow["AlbumName"]);

            string tooltip = MiscUtility.ToolTip1(ConvertUtility.ToString(currow["AlbumName"]), MultimediaUtility.GetGalleryAvatar(ConvertUtility.ToString(currow["AlbumAvatar"])), ConvertUtility.ToString(currow["AlbumDetail"]), "", ConvertUtility.ToDateTime(currow["CreateDate"]));
            hplTitle.Attributes.Add("onmouseover", "showtip('" + tooltip + "','322','#f1f1f1')");
            hplTitle.Attributes.Add("onmouseout", "hidetip()");

            if (Gallery_AlbumController.GetAllAlbumByParentID(ConvertUtility.ToInt32(currow["AlbumID"])).Rows.Count > 0)
            {
                hplTitle.NavigateUrl = BuildUrlByAlbum(ConvertUtility.ToInt32(currow["AlbumID"]));
            }
            else
            {
                hplTitle.NavigateUrl = BuildUrlByAlbum((int)currow["AlbumID"], zoneGalleryid);
            }
        }

        protected void rptBosnu_ItemDataBound1(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemIndex < 0) return;
            DataRowView currow = (DataRowView)e.Item.DataItem;
            Image imgPic = (Image)e.Item.FindControl("imgPic");
            imgPic.ImageUrl = ConvertUtility.ToString(currow["BonusAvatar"]) != string.Empty ? MultimediaUtility.GetBonusAvatar(ConvertUtility.ToString(currow["BonusAvatar"])) : "";
            if (imgPic.ImageUrl == "") imgPic.Visible = false;

            HyperLink hplTitle = (HyperLink)e.Item.FindControl("hplTitle");

            string tooltip = MiscUtility.ToolTip1(ConvertUtility.ToString(currow["BonusName"]), MultimediaUtility.GetBonusAvatar(ConvertUtility.ToString(currow["BonusAvatar"])), ConvertUtility.ToString(currow["BonusDescription"]), "", ConvertUtility.ToDateTime(currow["CreateDate"]));
            hplTitle.Attributes.Add("onmouseover", "showtip('" + tooltip + "','322','#f1f1f1')");
            hplTitle.Attributes.Add("onmouseout", "hidetip()");

            hplTitle.NavigateUrl = BuildUrlByBonusId((int)currow["BonusID"], zoneBonusid);
        }
    }
}